<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="cn.jhc.dao.ShopDAO"%>
<%@page import="cn.jhc.bean.UserBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="cn.jhc.bean.ShopBean"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/houtai.css"></link>
<title>订单信息</title>
</head>
<body>
	<div id="wrapper">
		<jsp:include page="./houtai_header.jsp"></jsp:include>
		<div id="left">
			<div class="button2"><a href="adminchecklist.jsp?judgment=T&judgment2=T">订单信息</a></div>
			<div class="button"><a href="houtai_addjita.jsp">增加吉他</a></div>
			<div class="button"><a href="deletejita.do?bl=all">删除吉他</a></div>
			<div class="button"><a href="alterjita.jsp">吉他信息</a></div>
		</div>
		<div id="right">
			<div id="right_top">
				<a>所在位置： 订单信息</a>
			</div>
			<%
				Date d = new Date();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String str = sdf.format(d);
				int y = Integer.parseInt(str.substring(0, 4));
				int m = Integer.parseInt(str.substring(5, 7));
				int r = Integer.parseInt(str.substring(8, 10));

				String judgment = request.getParameter("judgment");
				String judgment2 = null;
				judgment2 = request.getParameter("judgment2");
				if (judgment2.equals("F")) {
			%>
			<div align="center">
				<a><font color="red">没有相关信息请重新输入</font></a>
			</div>
			<%
				}
				if (!judgment.equals("F")) {
			%>

			<div align="center">
				<form action="adminchecklist.jsp?Page=1&judgment=F&judgment2=T"
					method="post">
					<table>
						<tr>

							<td><select size=1 name="years">
									<option value="">...</option>
									<%
										boolean bf = false;
											for (int yy = 2010; yy <= y; y--) {
									%>
									<option value="<%=y%>" <%if (!bf) {%> selected <%}%>><%=y%></option>
									<%
										bf = true;
											}
									%>

							</select></td>
							<td>年</td>

							<td><select size=1 name="month">
									<option value="">...</option>
									<%

										for (int mm = 1; mm <= 12; mm++) {											

									%>
									<option
										value="<%if (mm == 100) {%><%="0" + mm%>
								<%} else {%><%=mm%><%}%>"
										<%if (mm == m) {%> selected <%}%>><%=mm%></option>
									<%
										}
									%>

							</select></td>
							<td>月</td>

							<td><select size=1 name="th">
									<option value="">...</option>
									<%
										for (int rr = 1; rr <= 31; rr++) {
									%>
									<option
										value="<%if (rr == 100) {%><%="0" + rr%>
								<%} else {%><%=rr%><%}%>"
										<%if (rr == r) {%> selected <%}%>><%=rr%></option>
									<%
										}
									%>

							</select></td>
							<td>日</td>
						</tr>
					</table>
					<input type="submit" name="action" value="确定">
				</form>
			</div>

			<%
				} else {
					List<ShopBean> list = new ArrayList<ShopBean>();
					UserBean adminuser = (UserBean) session
							.getAttribute("adminuser");
					int Page = Integer.parseInt(request.getParameter("Page"));
					String years = request.getParameter("years");
					String month = request.getParameter("month");
					String th = request.getParameter("th");

					String date = null;
					date = request.getParameter("date");
					int Pagecount = 1;
					String datetime = null;
					if (date != null)
						datetime = date;
					else {
						if (years.equals("") && month.equals("") && !th.equals("")) {							
							if(Integer.parseInt(th)<10)
								th="0"+th;
							datetime = th;
						}
						if (years.equals("") && !month.equals("") && th.equals("")) {
							if(Integer.parseInt(month)<10)
								month="0"+month;
							
							datetime = month;
						}
						if (!years.equals("") && month.equals("") && th.equals("")) {
							datetime = years;
						}
						if (years.equals("") && !month.equals("") && !th.equals("")) {
							if(Integer.parseInt(month)<10)
								month="0"+month;
							if(Integer.parseInt(th)<10)
								th="0"+th;
							datetime = month + "-" + th;
						}
						if (!years.equals("") && month.equals("") && !th.equals("")) {
							datetime = years;
						}
						if (!years.equals("") && !month.equals("") && th.equals("")) {
							if(Integer.parseInt(month)<10)
								month="0"+month;
							datetime = years + "-" + month;
						}
						if (!years.equals("") && !month.equals("")
								&& !th.equals("")) {
							if(Integer.parseInt(month)<10)
								month="0"+month;
							if(Integer.parseInt(th)<10)
								th="0"+th;
							datetime = years + "-" + month + "-" + th;
						}
						System.out.println(datetime);
					}
					ShopDAO dao = null;
					if (null != adminuser) {
						dao = new ShopDAO();
						try {
							list = dao.adminChecklist(datetime);
						} catch (Exception e) {
							e.printStackTrace();
						}
						if (list.size() == 0) {
							RequestDispatcher dispatcher = request
									.getRequestDispatcher("/adminchecklist.jsp?judgment=T&judgment2=F");
							dispatcher.forward(request, response);
							return;
						} else {

							Pagecount = (list.size() + 12) / 13;
							request.setAttribute("list", list);
							request.setAttribute("Pagecount", Pagecount);
							request.setAttribute("Page", Page);
							request.setAttribute("years", years);
							request.setAttribute("month", month);
							request.setAttribute("th", th);
						}
					} else {
						String getb = (String) request.getParameter("getb");
						request.setAttribute("getb", getb);
						RequestDispatcher dispatcher = request
								.getRequestDispatcher("/houtai_login.jsp");
						dispatcher.forward(request, response);
						return;
					}
			%>
			<table width="100%" align="center">
				<tr>
					<th height="25">用户名</th>
					<th>班级</th>
					<th>地址</th>
					<th>联系人</th>
					<th>电话</th>
					<th>总价</th>
					<th>购物时间</th>
					<th>查看详情</th>
					<th>操作</th>
				</tr>
				<c:forEach items="${requestScope.list}" var="shop"
					begin="<%=(Page-1)*12%>" end="<%=Page*12%>">
					<tr>

						<td height="25" align="center">${shop.displayname}</td>
						<td align="center">${shop.class1}</td>
						<td align="center">${shop.address}</td>
						<td align="center">${shop.contact}</td>
						<td align="center">${shop.phone}</td>
						<td align="center">${shop.totalprice}</td>
						<td align="center">${shop.date}-${shop.time}</td>
						<td align="center"><a
							href="adminchecklistgoods.jsp?date=${shop.date}&time=${shop.time}&user=${shop.user}&Page=1&id=${shop.id}">查看</a></td>
						<td align="center"><a
							href="houtaideletelist.do?date=${shop.date}&time=${shop.time}&id=${shop.id}">删除</a></td>
					</tr>
				</c:forEach>
			</table>
			<div align="right">
				<a>第<%=Page%>页
				</a><a>共<%=Pagecount%>页
				</a>
				<%
					if (Page == 1) {
				%>
				<a>首页</a>
				<%
					} else {
				%>
				<a
					href="adminchecklist.jsp?Page=1&date=<%=datetime%>&judgment=F&judgment2=T">首页</a>
				<%
					}
				%>
				<%
					if (Page < 2) {
				%>
				<a>上一页</a>
				<%
					} else {
				%>
				<a
					href="adminchecklist.jsp?Page=<%=Page - 1%>&date=<%=datetime%>&judgment=F&judgment2=T">上一页</a>
				<%
					}
				%>
				<%
					if (Page < Pagecount) {
				%>
				<a
					href="adminchecklist.jsp?Page=<%=Page + 1%>&date=<%=datetime%>&judgment=F&judgment2=T">下一页</a>
				<%
					} else {
				%>
				<a>下一页</a>
				<%
					}
				%>
				<%
					if (Page == Pagecount) {
				%>
				<a>末页</a>
				<%
					} else {
				%>
				<a
					href="adminchecklist.jsp?Page=<%=Pagecount%>&date=<%=datetime%>&judgment=F&judgment2=T">末页</a>
				<%
					}
					}
				%>
			</div>
		</div>
	</div>
</body>

</body>
</html>